package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.PhenologicalperiodsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Phenologicalperiods;
import com.ruoyi.system.service.IPhenologicalperiodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作物物候期管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/system/phenologicalperiods")
public class PhenologicalperiodsController extends BaseController {
    @Autowired
    private IPhenologicalperiodsService phenologicalperiodsService;

    /**
     * 查询作物物候期管理列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Phenologicalperiods phenologicalperiods) {
//        startPage();
//        List<Phenologicalperiods> list = phenologicalperiodsService.selectPhenologicalperiodsList(phenologicalperiods);
//        return getDataTable(list);
        startPage();
        List<PhenologicalperiodsVo> list = phenologicalperiodsService.selectPhenologicalperiodsListVo(phenologicalperiods);
        return getDataTable(list);
    }


    /**
     * 导出作物物候期管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:phenologicalperiods:export')")
    @Log(title = "作物物候期管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Phenologicalperiods phenologicalperiods) {
        List<Phenologicalperiods> list = phenologicalperiodsService.selectPhenologicalperiodsList(phenologicalperiods);
        ExcelUtil<Phenologicalperiods> util = new ExcelUtil<Phenologicalperiods>(Phenologicalperiods.class);
        util.exportExcel(response, list, "作物物候期管理数据");
    }

    /**
     * 获取作物物候期管理详细信息
     */

    @GetMapping(value = "/{phenologicalperiodid}")
    public AjaxResult getInfo(@PathVariable("phenologicalperiodid") Long phenologicalperiodid) {
        return success(phenologicalperiodsService.selectPhenologicalperiodsByPhenologicalperiodid(phenologicalperiodid));
    }

    /**
     * 新增作物物候期管理
     */

    @Log(title = "作物物候期管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Phenologicalperiods phenologicalperiods) {
        return toAjax(phenologicalperiodsService.insertPhenologicalperiods(phenologicalperiods));
    }

    /**
     * 修改作物物候期管理
     */

    @Log(title = "作物物候期管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Phenologicalperiods phenologicalperiods) {
        return toAjax(phenologicalperiodsService.updatePhenologicalperiods(phenologicalperiods));
    }

    /**
     * 删除作物物候期管理
     */

    @Log(title = "作物物候期管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{phenologicalperiodids}")
    public AjaxResult remove(@PathVariable Long[] phenologicalperiodids) {
        return toAjax(phenologicalperiodsService.deletePhenologicalperiodsByPhenologicalperiodids(phenologicalperiodids));
    }

    // PhenologicalPeriodsController.java
    @GetMapping("/listByCropId")
    public AjaxResult listByCropId(@RequestParam Long cropid) {
        Phenologicalperiods query = new Phenologicalperiods();
        query.setCropid(cropid); // 不需要返回值
        List<Phenologicalperiods> list = phenologicalperiodsService.selectPhenologicalperiodsList(query);
        return AjaxResult.success(list);
    }


}

